local shenfo = fk.CreateSkill {
  name = "lingling__shenfo",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
  ["lingling__shenfo"] = "神佛",
  [":lingling__shenfo"] = "锁定技，摸牌阶段，你改为亮出牌堆顶五张牌，获得其中花色不同的牌各一张。",

  ["#lingling__shenfo-choose"] = "神佛：获得不同花色的牌各一张",
}

Fk:addPoxiMethod {
  name = "lingling__shenfo",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local suit = Fk:getCardById(to_select).suit
    return table.every(data[2], function(id)
      return Fk:getCardById(id).suit ~= suit
    end)
  end,
  feasible = Util.TrueFunc,
}

shenfo:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shenfo.name) and player.phase == Player.Draw and not data.phase_end
  end,
  on_use = function(self, event, target, player, data)
    data.phase_end = true
    local room = player.room
    local cards = room:getNCards(5)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = shenfo.name,
      proposer = player.id,
    })
    local get = {}
    for _, id in ipairs(cards) do
      local suit = Fk:getCardById(id).suit
      if table.every(get, function(id2)
            return Fk:getCardById(id2).suit ~= suit
          end) then
        table.insert(get, id)
      end
    end
    get = room:askToArrangeCards(player, {
      skill_name = shenfo.name,
      card_map = cards,
      prompt = "#lingling__shenfo-choose",
      free_arrange = false,
      box_size = 0,
      max_limit = { 5, 4 },
      min_limit = { 0, #get },
      poxi_type = "lingling__shenfo",
      default_choice = { {}, get },
    })[2]
    if #get > 0 then
      room:obtainCard(player, get, true, fk.ReasonPrey, player, shenfo.name)
    end
    room:cleanProcessingArea(cards)
  end,
})

return shenfo
